package com.demo.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
 * @ClassName
 * @Description 参数返回
 * @Version 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class BaseRes {
    private String code = "0";
    private String msg = "请求成功";
    private Object data;

    public BaseRes(Object data) {
        this.data = data;
    }

    public void setSuccess(String msg) {
        this.code = "0";
        this.msg = msg;
    }

    public void setSuccess(String msg,Object data) {
        this.code = "0";
        this.msg = msg;
        this.data = data;
    }

    public void setSuccess(Object data) {
        this.data = data;
    }

    public void setFail(String msg) {
        this.code = "-1";
        this.msg = msg;
    }



    public static BaseRes error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static BaseRes error(String msg) {
        return error(500, msg);
    }

    public static BaseRes error(int code, String msg) {
        BaseRes res = new BaseRes();
        res.setCode(String.valueOf(code));
        res.setMsg(msg);
        return res;
    }

    public static BaseRes ok(Object msg) {
        BaseRes r = new BaseRes();
        r.setMsg(msg.toString());
        return r;
    }



    public static BaseRes ok() {
        BaseRes r = new BaseRes();
        r.setMsg("操作成功");
        return r;
    }


}
